<template>
  <div class="">
    <input type="text" v-model="tit" @keydown.enter="search" />

    <ul>
      <li v-for="(item, index) in list" :key="index">{{ item.title }}</li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          title: "电竞椅",
          price: 270,
          num: 5,
        },
        {
          title: "电竞鼠标",
          price: 100,
          num: 8,
        },
        {
          title: "电竞键盘",
          price: 100,
          num: 6,
        },
      ],
      tit: "",
      copylist: [],
    };
  },
  mounted() {
    this.copylist = this.list;
    //在组件加载完成后自动备份一个数据
  },
  methods: {
    search() {
      this.list = this.copylist.filter((item) => {
        return item.title.includes(this.tit);
      });
    },
  },
  components: {},
};
</script>

<style lang="scss"></style>
